package com.skplanet.oneplusonewindow.moimserver.controller.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.skplanet.oneplusonewindow.moimserver.domain.Moim_Member;
import com.skplanet.oneplusonewindow.moimserver.domain.Moim_Moim;
import com.skplanet.oneplusonewindow.moimserver.domain.Moim_User;
import com.skplanet.oneplusonewindow.moimserver.service.MoimService;
import com.skplanet.oneplusonewindow.moimserver.service.UserService;


@Controller
public class MoimRedirectionController {
	
	@Autowired
	private UserService userService;

	@Autowired
	private MoimService moimService;
	
	@Autowired
	private MessageSource messageSource;
	
	@ResponseBody	
	@RequestMapping( value = "/moim/user/signup", method = RequestMethod.GET)
	public String signup(
			@RequestParam(value="name", required=true)String name,
			@RequestParam(value="nickName", required=true)String nickName,
			@RequestParam(value="passwd", required=true)String passwd) {	
			Moim_User user = new Moim_User();
			user.setName(name);
			user.setNickname(nickName);
			user.setPassword(passwd);
			userService.addUser(user);
		return "main";
	}
	
	@ResponseBody	
	@RequestMapping( value = "/moim/user/login", method = RequestMethod.GET)
	public String login(
			@RequestParam(value="name", required=true)String name) {	
//		
//		Moim_User user = userService.getUserFromName(name);
//		List<Moim_Moim> moims = user.getMoims();
//		int size = moims.size();
//		for(int i = 0 ; i < size ; i ++){
//			Moim_Moim moim = moims.get(i);
//			long id = user.getId();
//			Moim_Member member = moimService.getMemberFromUserId(id);
//			String pos = member.getPosition();
//		}
		
		return "logged";
	}
	
//	@ResponseBody
//	@RequestMapping( value = { "/json/user/addMoim", "/json/user/addMoim.json" }, method = RequestMethod.GET, headers = { "Accept=application/json"} )
//	public Map<String, Object> addMoim(
//			@RequestParam(value="name", required=true)String name,
//			@RequestParam(value="moimId", required=true)long moimId
//			) {
//		HashMap<String, Object> mapJSON = new HashMap<String,Object>();
//		
//		Moim_User user = moimService.addMoim(name, moimId);
//		
//		mapJSON.put("result", user);
//		
//		return mapJSON;
//	}
	
}